package com.duomai.myapplication.activity;

import android.app.AlertDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.duomai.myapplication.R;
import com.duomai.myapplication.base.BaseActivity;
import com.example.admin.SQLite.BaoMing;
import com.example.admin.SQLite.Complaint;
import com.example.admin.SQLite.SqLiteOpenHelper;
import com.example.admin.SQLite.dao.BaoMingDao;
import com.example.admin.bean.EventBean;
import com.orhanobut.hawk.Hawk;

import java.util.ArrayList;
import java.util.List;

public class EventsDetailActivity extends BaseActivity {
    BaoMing bean;
    TextView tvTitle, tvCont, tvStatu;
ImageView imgs;
    BaoMingDao baoMingDao;
    List<EventBean> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_events_detail);
        baoMingDao = new BaoMingDao(this);
        tvTitle = findViewById(R.id.tvTitle);
        tvCont = findViewById(R.id.tvCont);
        imgs = findViewById(R.id.imgs);
        tvStatu = findViewById(R.id.tvStatu);
        bean = (BaoMing) getIntent().getSerializableExtra("bean");
        tvTitle.setText(bean.title);
        tvCont.setText(bean.content);
        Glide.with(this).load(bean.imgPath).into(imgs);
        tvStatu.setText(bean.CreateData + "\nAdmin");
        findViewById(R.id.tvSure).setOnClickListener(v -> {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            View views = getLayoutInflater().inflate(R.layout.dialog_events, null);
            builder.setView(views);
            AlertDialog dialog = builder.create();
            dialog.show();
            EditText tvName = views.findViewById(R.id.tvName);
            EditText tvPhone = views.findViewById(R.id.tvPhone);
            Log.e("大师傅大师傅", "EventBeannum" + bean.id+"onClick: "+Hawk.get("EventBeannum" + bean.id) );
            views.findViewById(R.id.tvSure).setOnClickListener(v1 -> {
                list = new ArrayList<>();
                if (Hawk.contains("EventBean" + bean.id)){
                    list = Hawk.get("EventBean" + bean.id);
                }
                list.add(new EventBean(tvName.getText().toString().trim()
                        , tvPhone.getText().toString().trim()));
                Hawk.put("EventBean" + bean.id, list);
                String num = Hawk.get("EventBeannum" + bean.id);
                baoMingDao.updateComs(bean.id, "" + list.size() + "/" + num);
                dialog.dismiss();
                toast("报名成功");
            });
        });
    }

    @Override
    public void setContentView(Bundle savedInstanceState) {

    }

    @Override
    public void setInitView() {

    }
}